package com.lyk.dao.impl;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.common.dao.BaseDao;
import com.common.entity.A_timeRules;
import com.lyk.dao.A_timeRulesDao;

public class A_timeRulesDaoImpl extends BaseDao<A_timeRules> implements A_timeRulesDao {

	@Override
	public A_timeRules findById(Integer n) {
		List<Object> paramList=new ArrayList<Object>();
		StringBuffer sf=new StringBuffer();
		sf.append(" select * from a_timeRules where timeRules_id = ? ");
		paramList.add(n);
		List<A_timeRules> list = findBySql(sf.toString(), paramList.toArray());
		return (list!=null&&list.size()>0)?list.get(0):null;
	}

	@Override
	public int changetimeRules(A_timeRules timeRules) {
		String sql = "update a_timeRules set timeLimit=? where timeRules_id = ?";
		List<Object> paramList=new ArrayList<Object>();
		paramList.add(timeRules.getTimeLimit());
		paramList.add(timeRules.getTimeRules_id());
		return this.executeUpdate(sql, paramList.toArray());
	}

	@Override
	public List<A_timeRules> findByCondition(Map<String, Object> mp) {
		List<Object> paramList=new ArrayList<Object>();
		StringBuffer sf=new StringBuffer();
		sf.append(" select * from a_timeRules where 1=1 ");
		if(mp!=null && mp.size()>0){
				if(mp.get("atitle")!=null){
					sf.append("and title like ? ");
					paramList.add(mp.get("atitle"));
				}
		}
		return findBySql(sf.toString(), paramList.toArray());
	}
	public A_timeRules getEntity(ResultSet rs){
		try {
			A_timeRules timeRules = new A_timeRules();
			timeRules.setTimeRules_id(rs.getInt("timeRules_id"));
			timeRules.setTimeLimit(rs.getInt("timeLimit"));
			return timeRules;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return null;
	}
}
